require 'minitest/autorun'
require 'minitest/pride'
require 'fileutils'
require 'web_safe_filename'

# Test helpers

def generate_random_filename(length, start_char = 32)
  Array.new(length) { rand(start_char..126) }
    .reject {|i| [42,47,92].include?(i) }
    .map { |c| c.chr }.join
end

def generate_name_list
  list = []
  rand(1..30).times { list << generate_random_filename(30) }
  list
end

def generate_test_files
  Dir.mkdir('spec/test_files') unless Dir.exist?('spec/test_files')
  Dir.chdir('spec/test_files') do
    dirs = generate_name_list
    FileUtils.mkdir(dirs)
    dirs.each do |dir|
      Dir.chdir(dir) { FileUtils.touch(generate_name_list) }
    end
  end
end